import Api from '../Api'
import {controller, get, post} from "../../../decorator/decorator";
import {SMS_SEND,EXIST,AREA,EDIT_PASSWORD,CLOUDUPLOADURL,SUBMIT_COMPLAIN,MEMBERSHIP_FEE_TYPE, MEMBERSHIP_TRANSFER} from "../../../common/config/url";
import UUID from 'uuid-js'
import $ from 'jquery'
import {ABNORMAL} from "../../../common/config/code";
import lrz from 'lrz';

@controller('')
class Base extends Api{
  constructor(){
    super(Base);
  }
  @get(SMS_SEND)
  async smsSend(params){
    return await this.common(params)
  }
  @get(EXIST,false)
  async exist(params){
    return await this.common(params)
  }
  @get(AREA,false)
  async area(params){
    return await this.common(params)
  }
  @post(EDIT_PASSWORD)
  async editPassword(params){
    return await this.common(params)
  }
  @get(CLOUDUPLOADURL)
  async clouduplLoadUrl(params){
    try{
      let file=params.data;
      let uuid=UUID.create().hex
      params.params={
        key:uuid
      }
      delete params.data
      let data=await this.common(params);
      // const imgUrl = (data.data || '').replace('http', 'https')
      lrz(file)
        .then(function (rst) {
          // console.log(rst.file, 888)
          // return;
            return new Promise((resolve,reject)=>{
              if(data.data){
                $.ajax({
                  url: data.data,
                  type: "PUT",
                  cache: false,
                  contentType: false,// 告诉jQuery不要去设置Content-Type请求头
                  processData: false,// 告诉jQuery不要去处理发送的数据
                  data: rst.file,
                  success: function () {
                    params.success(uuid)
                    resolve(uuid)
      
                  },
                  error: function (err) {
                    reject(err)
                  }
                });
                // let config={
                //   baseURL:'',
                //   url:data.data,
                //   method:'put',
                //   data:file,
                //   headers:{
                //     'Content-Type':''
                //   },
                //   error:()=>{
                //
                //     params.success(uuid)
                //   }
                // }
                // return await this.common(config)
              }else{
                resolve(null)
              }
            })
        })
        .catch(function (err) {
            // 处理失败会执行
        })

    }catch (e) {
    }

  }

  @post(SUBMIT_COMPLAIN)
  async submitComplain(params){
    return await this.common(params)
  }
  @get(MEMBERSHIP_FEE_TYPE)
  async membershipFeeType(params){
    return await this.common(params)
  }
  @post(MEMBERSHIP_TRANSFER)
  async membershipTransfer(params){
    return await this.common(params)
  }
}
export default new Base()
